<template>
  <div class="chat">
    <div class="iptRow">
      <el-radio v-model="state" :label="0">等待回复</el-radio>
      <el-col style="width:10px"></el-col>
      <el-radio v-model="state" :label="1">已回复</el-radio>
    </div>
    <div class="record">
      <el-table :data="chatList" style="width: 100%">
        <el-table-column label="操作" width="60">
          <template slot-scope="scope">
            <el-link type="primary" @click="chat(scope.row)">回复</el-link>
          </template>
        </el-table-column>

        <el-table-column prop="wxName" label="微信名" width="100"></el-table-column>
        <el-table-column prop="startTime" label="咨询时间" width="200"></el-table-column>
        <el-table-column prop="appContent" label="咨询内容">
          <template slot-scope="scope">
            <span :title="scope.row.appContent">{{scope.row.appContent}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="回复时间" width="200"></el-table-column>
        <el-table-column prop="docContent" label="回复内容">
          <template slot-scope="scope">
            <span :title="scope.row.docContent">{{scope.row.docContent}}</span>
          </template>
        </el-table-column>
        <el-table-column prop label="评分" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.rate == -1 ? "未评价" : scope.row.rate }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        align="right"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageIndex"
        :page-sizes="[5, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="total"
        style="margin-top: 58px; margin-bottom: 40px"
      ></el-pagination>
    </div>
    <el-dialog title="回复" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form1" label-width="80px">
        <el-form-item label="回复内容">
          <el-input v-model="docContent" placeholder="请输入" type="textarea"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible3 = false">取 消</el-button>
        <el-button type="primary" @click="formConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    adminName: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      state: 0,
      chatList: [],
      chatId: 0,
      docContent: "",
      pageIndex: 1,
      pageSize: 10,
      dialogVisible: false,
      total: 20
    };
  },
  created() {
    this.getChatList();
  },
  watch: {
    state(val) {
      this.getChatByState(val);
    }
  },
  methods: {
    getChatList() {
      let params = {
        docName: this.adminName,
        state: this.state,
        docContent: "",
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      };
      console.log(params);
      this.$axios
        .get("/api/CjwChatList/DocGetMessage", { params })
        .then(res => {
          this.chatList = res.data.chatList;
          this.total = res.data.total;
        });
    },
    getChatByState(val) {
      console.log(val);
      let params = {
        docName: this.adminName,
        state: val,
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      };
      this.$axios
        .get("/api/CjwChatList/DocGetMessage", { params })
        .then(res => {
          this.chatList = res.data.chatList;
          this.total = res.data.total;
        });
    },
    chat(obj) {
      console.log(obj);
      this.chatId = obj.chatId;
      this.docContent = "";
      this.dialogVisible = true;
    },
    formConfirm() {
      console.log(this.docContent);
      let params = {
        chatId: this.chatId,
        docContent: this.docContent
      };
      this.$axios.post("/api/CjwChatList/DocSendMessage", params).then(res => {
        this.$message({
          type: "success",
          message: "回复成功!"
        });
        this.dialogVisible = false;
        this.getChatList();
      });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getChatList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getChatList();
    }
  }
};
</script>

<style scoped>
.iptRow {
  margin: 10px;
  display: flex;
  flex-direction: row-reverse;
}
.chat {
}
.page {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
}
</style>